package com.haochang.chunkvod.controller.activity.order;

import java.util.ArrayList;
import java.util.List;

import com.haochang.base.BaseActivity;
import com.haochang.chunkvod.R;
import com.haochang.chunkvod.app.database.order.BaseInfoDao;
import com.haochang.chunkvod.app.utils.CollectionUtils;
import com.haochang.chunkvod.app.utils.ToastUtils;
import com.haochang.chunkvod.controller.adapter.order.RemarkQueryAdapter;
import com.haochang.chunkvod.model.BaseInfo;
import com.haochang.chunkvod.model.order.OrderData;
import com.haochang.chunkvod.model.order.RoomInfo;
import com.haochang.chunkvod.view.thirdparty.PullToRefresh.PullToRefreshBase;
import com.haochang.chunkvod.view.thirdparty.PullToRefresh.PullToRefreshListView;
import com.haochang.chunkvod.view.vod.popupWindow.VodPopWindow;
import com.haochang.chunkvod.view.vod.title.TitleView;

import android.text.TextUtils;
import android.widget.ImageView;

/** 点餐--备注查询
 *     @author Yangjie
 *     className RemarkQueryListActivity
 *     created at  2016/11/18  17:21
 */
public class RemarkQueryListActivity extends BaseActivity
{
	private TitleView titleView;
	private PullToRefreshListView listView;
	private OrderData orderData;
	private RemarkQueryAdapter adapter;
	private List<RoomInfo> orderInfoList = new ArrayList<RoomInfo>();
	private List<BaseInfo> baseInfoList = new ArrayList<BaseInfo>();//颜色信息

	@Override
	public void receiveParam()
	{
	}

	@Override
	public void initData()
	{
		orderData = new OrderData(RemarkQueryListActivity.this);
		baseInfoList = BaseInfoDao.getDao().queryBuilderAll(BaseInfo.class, "is_room", true);
	}

	@Override
	public void initViews()
	{
		setContentView(R.layout.activity_remark_query_list);
		titleView = (TitleView) findViewById(R.id.titleView);
		listView = (PullToRefreshListView) findViewById(R.id.listView);
		listView.setMode(PullToRefreshBase.Mode.DISABLED);
		titleView.setTitle(R.string.remark_query).setTitleOnClickListener(new TitleView.ITitleOnClickListener()
		{
			@Override
			public void onBackClick()
			{
				finish();
				animRightToLeft();
			}

			@Override
			public void onDoneClick()
			{
				List<String> list = new ArrayList<String>();
				list.add("退出登录");
				int location[] = new int[2];
				ImageView img = (ImageView) titleView.findViewById(R.id.img_operates);
				img.getLocationOnScreen(location);
				int x = location[0];
				final VodPopWindow pop = new VodPopWindow(RemarkQueryListActivity.this, list);
				pop.showPopupWindow(titleView, x);
				pop.setPopWindowListListener(new VodPopWindow.OnPopWindowListListener()
				{
					@Override
					public void onSelectItem(int position)
					{
						switch (position)
						{
						case 0:
							loginOut();
							break;
						default:
							break;
						}
					}
				});
			}
		});
		adapter = new RemarkQueryAdapter(RemarkQueryListActivity.this, R.layout.item_order_remark_list, orderInfoList);
		adapter.setBaseInfoList(baseInfoList);
		listView.setAdapter(adapter);
		requestOrderRemarkList();
	}

	/**
	 * 获取点餐备注列表
	 */
	@SuppressWarnings("unchecked")
	private void requestOrderRemarkList()
	{
		orderData.requestOrderRemarkList(new OrderData.ResultResponseList()
		{
			@Override
			public void onRequestSuccess(List list)
			{
				listView.onRefreshComplete();
				if (!CollectionUtils.isEmpty(list))
				{
					orderInfoList.clear();
					orderInfoList.addAll(list);
					adapter.replaceAll(orderInfoList);
				}
			}

			@Override
			public void onFail(int errno, String errMsg)
			{
				listView.onRefreshComplete();
				ToastUtils.showText(RemarkQueryListActivity.this, TextUtils.isEmpty(errMsg) ? "获取备注信息失败!" : errMsg);
			}
		});
	}
}
